package com.cloud.tsp.controller;

import com.cloud.api.constants.StrVo;
import com.cloud.core.util.R;
import com.cloud.api.domain.tsp.QueryStatute;
import com.cloud.api.domain.tsp.Statute;

import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.service.IStatuteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-22
 */
@RestController
@RequestMapping("/statute")
public class StatuteController {

    @Resource
    private IStatuteService statuteService;

    @Tag(name = "v1.0")
    @Operation(summary = "查询规约信息（管理）")
    @PostMapping("/getStatuteList")
    @Log(title = "规约管理-查询规约信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public TableDataInfo<Statute> selectStatuteList(@RequestBody @Valid QueryStatute para){
        return statuteService.selectStatuteList(para);
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增或修改规约信息（管理）")
    @PostMapping("/InsertOrUpdate")
    @Log(title = "规约管理-新增或修改规约信息", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R InsertOrUpdate(@RequestBody @Valid Statute para){
        statuteService.saveOrUpdate(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除规约信息（管理）")
    @PostMapping("/deleteById")
    @Log(title = "规约管理-删除规约信息", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deleteById(@RequestBody @Valid StrVo para){
        statuteService.removeById(para.getId());
        return R.ok();
    }
}